package com.easyUploader.controller;

import com.common.mybaits.CustomPage;
import com.common.result.ResponseResultAdvice;
import com.easyUploader.assembler.BucketAssembler;
import com.easyUploader.entity.dto.BucketDto;
import com.easyUploader.entity.dto.FileDto;
import com.easyUploader.entity.vo.BucketVo;
import com.easyUploader.property.LocalFileProperty;
import com.easyUploader.service.IBucketService;
import com.easyUploader.service.IFileStorageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 大忽悠
 * @create 2022/9/15 11:09
 */
@Validated
@RestController
@RequestMapping("/bucket")
@RequiredArgsConstructor
@ResponseResultAdvice
@Api(tags = "存储桶")
public class BucketController {
    private final IBucketService iBucketService;

    @ApiOperation("创建存储桶")
    @PostMapping("/create")
    public Boolean createBucket(BucketVo bucketVo){
          return iBucketService.create(bucketVo);
    }

    @ApiOperation("查询存储桶")
    @GetMapping("/list")
    public List<BucketDto> listBucket(CustomPage customPage){
        return iBucketService.list(customPage);
    }

    @ApiOperation("查询当前桶某个目录层级下的文件信息")
    @GetMapping("/listDirFileInfo")
    public List<FileDto> listFileInfo(@ApiParam("桶名") String bucketName,@ApiParam("目录路径") String dir, CustomPage customPage){
        return iBucketService.listFileInfo(bucketName,dir,customPage);
    }

    @ApiOperation("设置存储桶类型")
    @GetMapping("/setBucketType")
    public Boolean setBucketType(@RequestParam("id")@ApiParam("桶的id") Integer id,
                                 @RequestParam("type")@ApiParam("桶的读写状态: 0-只读,1-读写") Integer type){
        return iBucketService.setBucketType(id,type);
    }

    @ApiOperation("删除存储桶")
    @DeleteMapping("/delete")
    public Boolean deleteBucket(@RequestParam("id")@ApiParam("桶id") Integer id){
        return iBucketService.delete(id);
    }
}
